package com.thf.participle;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
public class IkParticiple {

    @RequestMapping("/es/ik")
    public void participle(HttpServletResponse httpServletResponse){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        httpServletResponse.setDateHeader("Last-Modified",System.currentTimeMillis()+1);
        httpServletResponse.setHeader("ETag", df.format(new Date()));
        httpServletResponse.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
        try (
                FileInputStream fis = new FileInputStream("D:/elasticsearch/participle.txt");
                OutputStream os = httpServletResponse.getOutputStream()
            ){
            byte[] bytes = new byte[1024*8];
            int len = fis.read(bytes);
            while (len != -1){
                os.write(bytes, 0, len);
                len = fis.read(bytes);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
